home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / util / transThreadDeath.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  3.4 KB  |  129 lines

  1. /*
  2.  *   $RCSfile: transThreadDeath.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:03 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include "sysdefs.h"
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "trace.h"
  42. #include "error.h"
  43. #include "io.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "lock.h"
  47. #include "object.h"
  48. #include "msgdefs.h"
  49. #include "thread.h"
  50. #include "semaphore.h"
  51. #include "link.h"
  52. #include "lsn.h"
  53. #include "latch.h"
  54. #include "bf.h"
  55. #include "volume.h"
  56. #include "trans.h"
  57. #include "bitvec.h"
  58. #include "msgvector.h"
  59. #include "threadstate.h"
  60. #include "msg_funcs.h"
  61. #include "thread_funcs.h"
  62. #include "thread_globals.h"
  63. #include "msg_globals.h"
  64. #include "server_util_funcs.h"
  65.  
  66.  void
  67. transThreadDeath (
  68.  
  69.     register TCB        *tcb 
  70. )
  71. {
  72.     TRACE(TR_MSG, TR_LEVEL_1);
  73.  
  74.     /*
  75.      *    check to see if this thread is running as part of a transaction
  76.      */
  77.     if (LIST_MEMBER( &(tcb->transList) ))    {
  78.         register TRANSREC    *transRec;
  79.  
  80.         TRPRINT(TR_MSG|TR_TRANS, TR_LEVEL_2, ("transaction thread"));
  81.  
  82.         /*
  83.          *    get a pointer to the transaction record
  84.          */
  85.         transRec = (TRANSREC *) tcb->transRec;
  86.         CHECK_TRANSREC_MAGIC(transRec);
  87.  
  88.         /*
  89.          *    remove it from the list and decrement count
  90.          */
  91.         listRemove( &(tcb->transList) );
  92.         transRec->threadCount--;
  93.         tcb->transRec = NULL;
  94.  
  95.         /*
  96.          *    If this thread is holding the transaction log semaphore,
  97.          *    then release the semaphore.
  98.          */
  99.         if (transRec->logSemaphore.holder == Active) {
  100.             signalSemaphore(&(transRec->logSemaphore));
  101.         }
  102.  
  103.         /*
  104.          *    if we are the last thread (ie. only master left) then we
  105.          *    must signal the master thread that completion is ready
  106.          *
  107.          *    The master thread is not on the transaction thread
  108.          *    list, so it does not add one to the threadCount.
  109.          */
  110.         if (transRec->transState == T_QUIESCE && transRec->threadCount == 0)    {
  111.  
  112.             TRPRINT(TR_MSG|TR_TRANS, TR_LEVEL_2, ("signalling master"));
  113.  
  114.             /*
  115.              *    signal the master
  116.              */
  117.                SM_ASSERT(LEVEL_3, transRec->masterThread->state == THREAD_TRANS_QUIESCE_WAIT);
  118.             listMoveEnq( &ReadyList, &(transRec->masterThread->controlList) );
  119.         }
  120.  
  121.     } else {
  122.  
  123.         /*
  124.          *    null out the transrec pointer
  125.          */
  126.         tcb->transRec = NULL;
  127.     }
  128. }
  129.